package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVo {

    //收获地址列表
    @Setter @Getter
    List<MemberAddressVo> address;
    //所有购物项
    @Setter @Getter
    List<OrderItemVo> items;
    //发票。。。

    //优惠券信息...
    @Setter @Getter
    Integer integration;

    //防重令牌
    @Setter @Getter
    String orderToken;

    @Setter @Getter
    Map<Long,Boolean> stocks;

    public Integer getCount(){
        Integer i=0;
        if (items!=null) {
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    //订单总额
//    BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items!=null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum=sum.add(multiply);
            }
        }
        return sum;
    }

    //应付价格
//    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    @Override
    public String toString() {
        return "OrderConfirmVo{" +
                "address=" + address +
                ", items=" + items +
                ", integration=" + integration +
                ", orderToken='" + orderToken + '\'' +
                ", stocks=" + stocks +
                '}';
    }
}
